package com.web.base.wechat.dao;

import com.blue.jdbc.BaseDao;
import com.web.base.wechat.model.SendTemplate;
import org.springframework.stereotype.Repository;

@Repository("wechatSendTemplateDao")
public class SendTemplateDao extends BaseDao<SendTemplate>
{
	public SendTemplateDao()
	{
	}

	@Override
	protected void query(StringBuilder sql, SendTemplate param)
	{
		if (param != null)
		{
			if (param.getWechatId() != null && param.getWechatId() > 0)
				sql.append(" and a.wechat_id=:wechatId");

			if (param.getTemplateId() != null && param.getTemplateId() > 0)
				sql.append(" and a.template_id=:templateId");

		}
		sql.append(" order by a.id desc");
	}

	@Override
	protected StringBuilder select()
	{
		StringBuilder sql = new StringBuilder(64);
		sql.append("select a.*, w.name wechat_name, t.name template_name from wx_send_template a");
		sql.append(" left join wx_wechat w on w.id=a.wechat_id");
		sql.append(" left join wx_wechat_template t on t.id=a.template_id");
		sql.append(" where 1=1");
		return sql;
	}
}
